package com.cskaoyan._07initialization._02classload;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/9 11:45
 **/
/*
类加载时机:
1.main方法
2.首次new对象
3.访问类中的静态的成员
4.子类加载的时候,先触发父类的加载(从祖先类开始加载,一直到该子类)
 */
public class Demo {
    public static void main(String[] args) {
        GrandSon grandSon = new GrandSon();
    }
}

class GrandFather {
    static {
        System.out.println("GrandFather.static initializer");
    }

    public GrandFather() {
        System.out.println("GrandFather 构造方法");
    }
}

class Father extends GrandFather {
    static {
        System.out.println("Father.static initializer");
    }

    public Father() {
        System.out.println("Father 构造方法");
    }
}

class Son extends Father {
    static {
        System.out.println("Son.static initializer");
    }

    public Son() {
        System.out.println("Son  构造方法");
    }
}

class GrandSon extends Son {
    static {
        System.out.println("GrandSon.static initializer");
    }

    public GrandSon() {
        System.out.println("GrandSon 构造方法");
    }
}